package com.briup.ch10;

/**
 * @Author briup-adam
 * @Date 2023/10/27 下午2:31
 * @Description
 **/

public class TicketRunnable implements Runnable {
    int num = 50;
    String s = "高斌";

    @Override
    public void run() {

        while (true) {
            //_____  ++++++++
            synchronized (s) {
                if (num<=0)
                    break;

                Thread thread = Thread.currentThread();
                String name = thread.getName();
                num--;
                System.out.println(name + "进行售票。剩余：" + num);
            }

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        TicketRunnable r = new TicketRunnable();
        Thread t1 = new Thread(r, "一号窗口");
        Thread t2 = new Thread(r, "二号窗口");
        Thread t3 = new Thread(r, "三号窗口");
        t1.start();
        t2.start();
        t3.start();

    }

}
